import requests
from openai import OpenAI
from util.api_util import get_yml_key

basic_url = "https://api.siliconflow.cn/v1"
url = "https://api.siliconflow.cn/v1/chat/completions"
key_name = "siliconflow"

qwen_think_model_name = "Qwen/QwQ-32B"

qwen_free_model_name = "Qwen/Qwen3-8B"


def basic_message():
    return [
        {
            "role": "user",
            "content": "What's the best llm model in 2025? just give me the name"
        }
    ]


def by_rest():
    key = get_yml_key(key_name)

    payload = {
        "model": qwen_free_model_name,
        "messages": basic_message(),
        "max_tokens": 1024,
        "thinking_budget": 4096,
        "top_p": 0.7
    }

    headers = {
        "Authorization": f"Bearer {key}",
        "Content-Type": "application/json"
    }

    response = requests.post(url, json=payload, headers=headers)

    print(response.json())


def by_openai():
    key = get_yml_key(key_name)
    client = OpenAI(api_key=key, base_url=basic_url)

    response = client.chat.completions.create(
        model=qwen_free_model_name,
        messages=basic_message(),
        # messages=[
        #     {"role": "system", "content": "You are a helpful assistant"},
        #     {"role": "user", "content": "Hello"},
        # ],
        max_tokens=1024,
        temperature=0.7,
        stream=False
    )

    print(response.choices[0].message.content)


if __name__ == '__main__':
    by_rest()

    # write something

    # by_openai()
